/**
 * Licensed under the Apache License Version 2.0.
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */
package net.interknit.knitter.cg;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;

/**
 *
 */
public class CodeGenTask extends Task
{
	private String cgconfig;
	private String basepackagename;
	private String outputdir;
	private String author;
	private String usequalifiedtypenames;
	private String excludedTypes;
	private String ignoredTypes;
	private String logpriority;
	private String failonerror;

	@Override
	public void execute() throws BuildException
	{
		try
		{
			int logPriority = CGMain.LOG_PRIORITY_WARN;

			try
			{
				logPriority = new Integer(logpriority).intValue();
			}
			catch(Exception e)
			{
				;
			}

			CGMain.run(
					cgconfig,
					basepackagename,
					outputdir,
					author,
					new Boolean(usequalifiedtypenames).booleanValue(),
					excludedTypes,
					ignoredTypes,
					logPriority,
					getProject());
		}
		catch(Exception e)
		{
			if(new Boolean(failonerror))
				throw new BuildException(e);
			else
				CGMain.getInstance().log("CodeGenTask failed", e, CGMain.LOG_PRIORITY_WARN);
		}
	}

	public String getCgconfig()
	{
		return this.cgconfig;
	}

	public void setCgconfig(String cgconfig)
	{
		this.cgconfig = cgconfig;
	}

	public String getBasepackagename()
	{
		return this.basepackagename;
	}

	public void setBasepackagename(String basepackagename)
	{
		this.basepackagename = basepackagename;
	}

	public String getOutputdir()
	{
		return this.outputdir;
	}

	public void setOutputdir(String outputdir)
	{
		this.outputdir = outputdir;
	}

	public String getAuthor()
	{
		return this.author;
	}

	public void setAuthor(String author)
	{
		this.author = author;
	}

	public String getUsequalifiedtypenames()
	{
		return this.usequalifiedtypenames;
	}

	public void setUsequalifiedtypenames(String usequalifiedtypenames)
	{
		this.usequalifiedtypenames = usequalifiedtypenames;
	}

	public String getExcludedTypes()
	{
		return this.excludedTypes;
	}

	public void setExcludedTypes(String excludedTypes)
	{
		this.excludedTypes = excludedTypes;
	}

	public String getIgnoredTypes()
	{
		return this.ignoredTypes;
	}

	public void setIgnoredTypes(String ignoredTypes)
	{
		this.ignoredTypes = ignoredTypes;
	}

	public String getLogpriority()
	{
		return this.logpriority;
	}

	public void setLogpriority(String logpriority)
	{
		this.logpriority = logpriority;
	}

	public String getFailonerror()
	{
		return this.failonerror;
	}

	public void setFailonerror(String failonerror)
	{
		this.failonerror = failonerror;
	}
}
